package classAndMonitor;
import javax.persistence.*;
public class OneToOneExample {
    public static void main(String[] args) {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("ClassAndMonitor");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();

        MonitorEntity m1 = new MonitorEntity();
        m1.setM_id(1000);
        m1.setM_name("乔寿凯");
        m1.setM_age(17);

        MonitorEntity m2 = new MonitorEntity();
        m2.setM_id(1001);
        m2.setM_name("吴凯");
        m2.setM_age(18);

        em.persist(m1);
        em.persist(m2);

        ClassEntity c1 = new ClassEntity();
        c1.setC_id(1001);
        c1.setC_name("软件191");
        c1.setMonitorEntity(m1);


        ClassEntity c2 = new ClassEntity();
        c2.setC_id(1002);
        c2.setC_name("软件192");
        c2.setMonitorEntity(m2);

        em.persist(c1);
        em.persist(c2);

        em.getTransaction().commit();
        em.close();
        emf.close();
    }
}
